
#ifndef _MEMBER_BSIXDOFRESTRAINT_H_
#define _MEMBER_BSIXDOFRESTRAINT_H_

#include <BNode>
#include <BSixdofRestraint>

#define sixdof_member(sixdof)		((member_BSixdofRestraint*)((BSixdofRestraint*)sixdof)->_ptr)

namespace BWE
{
	struct LimitMotor
	{
		BRealRange range;
		bool enabled = false;
		BReal motorTarget = 0;
		BReal motorVelocity = 0;
		BReal motorMaxForce = 6;
		BReal maxLimitForce = 300;
		BReal currentValue = 0;
		BReal limitError = 0;
		bool limited = false;

	};

	class member_BSixdofRestraint
	{
	public:
		member_BSixdofRestraint(BSixdofRestraint* restraint);
		~member_BSixdofRestraint();

		void calculateTransforms();
		void applyAngularLimit(BReal stepTime, BSolverItem& solverItem, LimitMotor& limitMotor, const BVector& axis);
		void applyLinearLimit(BReal stepTime, BSolverItem& solverItem, LimitMotor& limitMotor, const BVector& axis, int rotAllowed);

		BSixdofRestraint*	boss;

		LimitMotor			linearLimits[3];
		LimitMotor			angularLimits[3];
		bool				springEnabled[6];
		BReal				equilibriumPoint[6];
		BReal				springStiffness[6];
		BReal				springDamping[6];

		BVector				calculatedAxis[3];
		bool				useLinearReferenceFrameA;

	};
}

#endif
